/**
 * withList: 高阶组件工厂 this.props是xxx父组件调用titleList时传入的参数
 * titleList: 高阶组件 this.props是withList组件中传入的参数{...this.props, list}
 * xxx: 父组件
*/
import React from "react"

export default function WithList (Component, getList) {
  class WithList extends React.Component {
    state = {
      list: []
    }
    async componentDidMount () {
      const list = await getList()
      this.setState({
        list
      })
    }
    render () {
      return (
        <Component
          {...this.props}
          list={this.state.list}>
        </Component>
      )
    }
  }
  // return forwardRef((props, myRef) => {
  //   return <WithList {...props} myRef={myRef} />
  // })
  return WithList
}